package ezXpns.storage.queries;

import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;

import ezXpns.storage.Query;


//@author A0088827L
public class ComboQuery<T> implements Query<T> {

	public ComboQuery(Iterable<Query<T>> queries) {
		this.queries = queries;
		luceneQuery = new BooleanQuery();
		for(Query<T> query: queries) {
			luceneQuery.add(query.asLuceneQuery(), Occur.MUST);	
		}
	}

	@Override
	public boolean apply(T arg) {
		for(Query<T> query: queries) {
			if(!query.apply(arg))
				return false;
		}
		return true;
	}

	@Override
	public org.apache.lucene.search.Query asLuceneQuery() {
		return luceneQuery;
	}

	private Iterable<Query<T>> queries;
	private BooleanQuery luceneQuery;
}
